package br.com.Dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import br.com.Conexao.conexao;

public class LoginDao {
	
	Connection connection;
	
	public LoginDao(){
		
		this.connection = new conexao().getConnection();
		
	}
	
	public int validerLogin(String login , String senha){
		
		String sql = "select idUsuarioCliente id "+
		             "from tb_usuario_cliente "+
				
				     "where login='"+login+"' and senha='"+senha+"' "+
		             "union "+
				     "select idUsuarioComerciante id "+
		             "from tb_usuario_comerciante "+
		             "where login='"+login+"' and senha='"+senha+"' ";
		
		PreparedStatement stmt;
		try {
			stmt = (PreparedStatement) this.connection.prepareStatement(sql);
			ResultSet rs= stmt.executeQuery();
			
			while(rs.next()){

						    
		          return rs.getInt("id");
			     
		   }
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
    	
		return 0;
		
	
		
		
	}

}
